/*
 * Created on Jan 3, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package bmoofxbridge.model;

import net.ofx.types.x2003.x04.AccountEnum;
import net.ofx.types.x2003.x04.BankAccount;

import com.develop.jawin.COMException;

import bmoofxbridge.BMOParser;

/**
 * @author leonidr
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class Account {
	public static short[] AccountId = new short[] {2,0};
	public static short[] BankName = new short[] {2,1};
	public static short[] BankBranchName = new short[] {2,2};

    protected String accountID;
    protected String bankName;
    protected String brunchName;
    
    
	
	/**
	 * @param bankName
	 * @param brunchName
	 * @param accountID
	 */
	public Account(String bankName, String brunchName, String accountID) {
		this.bankName = bankName;
		this.brunchName = brunchName;
		this.accountID = accountID;
	}
	/**
	 * @throws COMException
	 * 
	 */
	public Account(BMOParser parser) throws COMException {	    
	    this(parser.getValue(BankName),
	    	 parser.getValue(BankBranchName),
			 parser.getValue(AccountId));        
	}
	
    /**
     * @return Returns the accountID.
     */
    public String getAccountID() {
        return accountID;
    }
    /**
     * @return Returns the bankName.
     */
    public String getBankName() {
    	if (null!=bankName)
    		return bankName;
    	else
    		return "NONE";    	
    }
    /**
     * @return Returns the brunchName.
     */
    public String getBrunchName() {
    	if (null!=brunchName)
    		return brunchName;
    	else
    		return "NONE";          
    }
    
    public BankAccount getBankAccount(){
        BankAccount account = BankAccount.Factory.newInstance();		
		
		account.setACCTID(getAccountID());
		account.setACCTKEY(getAccountID());
		account.setACCTTYPE(AccountEnum.CHECKING);
		account.setBANKID("POALIM");
		account.setBRANCHID("NONE");
		return account;
    }
    
    
	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	public boolean equals(Object obj) {
		try{
			return getAccountID().equals(((Account)obj).getAccountID());
		}
		catch (Exception e) {
			return false;
		}
			
	}
	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		return getAccountID().hashCode();
	}
}
